<template lang="">
    <div class="photoinfo-container">
        <h3>{{photoInfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间: {{photoInfo.add_time | dateFormat}}</span>
            <span>点击 : {{photoInfo.click}} 次</span>
        </p>
        <hr>
        <!-- 缩略图区域 -->
        <div class="thumbs">
            <img class="preview-img" v-for="(item, index) in list" :key="item.src" :src="item.src" height="100"
            @click="$preview.open(index, list)">
        </div>
        
        <!-- 图片内容区域 -->
        <div class="content" v-html="photoInfo.content">

        </div>
        <!-- 评论子组件,使用现成的 -->
        <comment v-bind:parentid="id"></comment>
    </div>
</template>
<script>
    //1.导入评论子组件
    import comment from '../subcomponents/comment.vue'
    export default {
        data() {
            return {
                id: this.$route.params.id,
                photoInfo: {},
                list: []
            }
        }, methods: {
            getPhotoIfo() {
                //获取图片详情
                this.$http.get("api/getimageInfo/" + this.id).then(result => {
                    debugger;
                    var result = result.body;
                    if (result.code === 200) {
                        this.photoInfo = result.data;
                    }
                })
            },
            getThumbs() {
                //获取缩略图
                this.$http.get("api/getthumimages/"+ this.id).then(result => {
                    var result = result.body;
                    if (result.code === 200) {
                    //循环每一个图片数据，补全图片的宽和高
                    result.datas.forEach(item=>{
                        item.w=600;
                        item.h=400;
                    })
                    this.list = result.datas;
                    }
                }) 
            }
        },
        created() {
            this.getPhotoIfo();
            this.getThumbs();
        },
        components: {
            comment
        }
    }
</script>
<style lang="scss" scoped>
    .photoinfo-container {
        padding: 3px;
        /*最外层 不贴边*/


        h3 {
            color: #26a2ff;
            font-size: 15px;
            text-align: center;
            margin: 15px 0;
        }

        .subtitle {
            display: flex;
            /*设置弹性盒子模型*/
            justify-content: space-between;
            /* 两端对齐*/
        }

        .content {
            font-size: 13px;
            line-height: 30px;
        }

        .thumbs{
            img{
                margin: 10px;/*撑开图片*/
                box-shadow: 0 0 9px #999;/*设置边框阴影*/
            }
        }
    }
</style>